package com.ias.agdis_r.adapter;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ias.agdis_r.bean.fight.Query;
import com.ias.agdis_r.manager.JavaBeanManager;
import com.ias.agdis_r.module.ParameterModel;
import com.ias.agdis_r.util.S;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class InitAutoTaskListAdapter extends BaseAdapter {

    private Context context;
    private List<Query> list;

    private Map<String, String> mDataResType = new HashMap<String, String>();
    private Map<String, String> mDataLockType = new HashMap<String, String>();

    public InitAutoTaskListAdapter(Context context, List<Query> list) {
        this.context = context;
        this.list = list;
        loadData();
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(android.R.layout.simple_list_item_2, parent, false);
        }
        TextView text1 = (TextView) convertView.findViewById(android.R.id.text1);
        TextView text2 = (TextView) convertView.findViewById(android.R.id.text2);
        Query query = list.get(position);
        text2.setText(mDataResType.get(query.getRTP()));
        text1.setText(mDataLockType.get(query.getTYPE()) + ": " + query.getVALUE());
        return convertView;
    }

    private void loadData() {
        mDataResType.clear();
        mDataLockType.clear();

        String sRtl = JavaBeanManager.getInstance().getUserinfo().getRtl();
        try{
            String[] sRtlArray = sRtl.split(",");
            for (int n = 0; n < sRtlArray.length - 1; n = n + 2) {
                mDataResType.put(sRtlArray[n], sRtlArray[n + 1]);
            }
            for (int i = 0; i < ParameterModel.LOCKTYPENAMEMAP.length; i++) {
                mDataLockType.put(ParameterModel.LOCKTYPENAMEMAP[i][0], ParameterModel.LOCKTYPENAMEMAP[i][1]);
            }
        }catch (NullPointerException e){
            Log.w("C_autoTask"," JavaBeanManager.getInstance().getUserinfo().getRtl() returnn null");
            e.printStackTrace();
        }


    }

}
